﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.b10_jgmxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void b10_jgmx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            b10_jgmxMgr mgr = new b10_jgmxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_b10_jgmx(e.Parameters[b10_jgmx_Filter.ParamPrefix]));
            IList<b10_jgmx> list = mgr.FindAllByPage_b10_jgmx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[b10_jgmx_Filter.ParamPrefix]);
            b10_jgmx_MainStore.DataSource = list;
            b10_jgmx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            b10_jgmxMgr mgr = new b10_jgmxMgr();
            RowSelectionModel sm = b10_jgmx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                b10_jgmx _b10_jgmx = new b10_jgmx();
                _b10_jgmx.orgmxid = int.Parse(row.RecordID);
                if (mgr.Del_b10_jgmx(_b10_jgmx))
                {
                    log.Debug("b10_jgmx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            b10_jgmx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            b10_jgmxMgr mgr = new b10_jgmxMgr();
            b10_jgmx _b10_jgmx = new b10_jgmx();
            if (Hid.Text.Length > 0)
                _b10_jgmx = mgr.FindById_b10_jgmx(int.Parse(Hid.Text));
            
			_b10_jgmx.orgid = Txtorgid.Text.Trim();
			_b10_jgmx.account = Txtaccount.Text.Trim();
			_b10_jgmx.inputsum = Txtinputsum.Text.Trim();
			_b10_jgmx.doorbala = Txtdoorbala.Text.Trim();
			_b10_jgmx.hosbala = Txthosbala.Text.Trim();
			_b10_jgmx.bigillbala = Txtbigillbala.Text.Trim();
			_b10_jgmx.riskbala = Txtriskbala.Text.Trim();
			_b10_jgmx.expendsum = Txtexpendsum.Text.Trim();
			_b10_jgmx.tranpeo = Txttranpeo.Text.Trim();
			_b10_jgmx.tranunit = Txttranunit.Text.Trim();
			_b10_jgmx.trandate = Txttrandate.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_b10_jgmx(_b10_jgmx);
            else
                isok = mgr.Add_b10_jgmx(_b10_jgmx);
            if (isok)
            {
                b10_jgmx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("b10_jgmx中执行了保存（插入或修改），并成功");
                b10_jgmx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}